using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;


namespace SampleApp
{
    static class MessageBox
    {
        public static void Show( string msg )
        {
            ShowDialog( "", msg );
        }

        public static void Show( string msg, string title )
        {
            ShowDialog( title, msg );
        }

        public static void Show( Exception ex )
        {
            var sb = new StringBuilder();
            sb.Append( ex.Message );
            while( ex.InnerException != null )
            {
                ex = ex.InnerException;
                sb.Append( System.Environment.NewLine + System.Environment.NewLine );
                sb.Append( ex.Message );
            }
            ShowDialog( "Error", sb.ToString() );
        }

        static void ShowDialog( string title, string msg )
        {
            AlertDialog.Builder dlgAlertBuilder = new AlertDialog.Builder( MainActivity.TheMainActivity );

            dlgAlertBuilder.SetMessage( msg );
            dlgAlertBuilder.SetTitle( title );
            dlgAlertBuilder.SetPositiveButton( "OK", ( s, ev ) =>
            {
            } );
            dlgAlertBuilder.SetCancelable( true );
            dlgAlertBuilder.Create().Show();
        }
    }
}
